package com.cn.jx.manager.dao;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.cn.jx.manager.po.RoleResource;
import com.cn.jx.manager.po.User;
import com.cn.jx.manager.po.UserOrgJob;
import com.cn.jx.manager.po.UserRole;

/**
 * <p>UserRoleRepository 用户角色关系操作mapper层操作数据库的接口
 * <p>实现<{@link BaseIdRepository <tt>公用</tt>}}
 * 
 * @author <h1>jiangxu2  2019年11月21日</h1>
 * @version v1.11.20.2019
 * @since 1.0
 * 
 */
public interface UserRoleRepository extends JpaRepository<UserRole,String>,JpaSpecificationExecutor<UserRole>{
	
	/**<p>定义HQL查询 根据人员id删除关联关系 {@link UserOrgJob}*/
	@Modifying
	@Query("delete UserRole rc where rc.userId in(:uids) ")
	public void deleteRealationByUserIds(@Param(value="uids") List<String> uids);
	
	/**<p>定义HQL查询 根据人员id删除关联关系 {@link UserOrgJob}*/
	@Modifying
	@Query("delete UserRole where userId =:uid ")
	public void deleteRealationByUserId(@Param(value="uid") String uid);
	
	/**<p>定义HQL查询 根据角色id和资源id删除关联关系 {@link RoleResource}*/
	@Modifying
	@Query("delete UserRole where roleId in(:roleIds) ")
	public void deleteRealationByRoleIds(@Param("roleIds")List<String> roleIds);
	
	/**<p>定义HQL查询 根据登录名查询用户对象 有效的用户 {@link User} */
	@Query("select roleId from UserRole  where userId=:uid ")
	public List<String> findUserRoleByUserId(@Param(value = "uid") String uid);
}
